//
//  GoldenVPNPayModelHandle.m
//  QLadder
//
//  Created by xiongguobing on 2019/9/19.
//  Copyright © 2019 qding. All rights reserved.
//

#import "GoldenVPNPayModelHandle.h"
#import <AlipaySDK/AlipaySDK.h>

@implementation GoldenVPNPayModelHandle

+ (void)payWithOrderNo:(NSString *)orderNo payType:(NSInteger)payType
{
    [kNetworkUtil postWithModuleURLStr:tradeOrder parameters:@{@"orderNo" : orderNo, @"payType" : @(payType)} success:^(id response) {
        if ([response[@"code"] integerValue] == networkSuccessStatus) {
            NSString * pay = response[@"url"];
            if (payType == 1) {
                [self alipayWithPaySign:pay];
            }else if (payType == 2){
                
            }else if (payType == 3){
                [kApplication openURL:[NSURL URLWithString:pay]];
            }
        }
    } failure:nil withHud:YES];
}

+ (void)alipayWithPaySign:(NSString *)paySign
{
    NSString * appScheme = @"backCNVPN";
    [[AlipaySDK defaultService] payOrder:paySign fromScheme:appScheme callback:^(NSDictionary *resultDic) {
        NSLog(@"alipayyyyyyyyyyyyyyyyyyyyy reslut = %@",resultDic);
        NSString *result = resultDic[@"result"];
        if (result.length>0) {
            NSDictionary * jsonDic = [result mj_JSONObject];
            NSDictionary * alipay_trade_app_pay_response = jsonDic[@"alipay_trade_app_pay_response"];
            if ([alipay_trade_app_pay_response[@"code"] integerValue] == 10000) {
                kShowWithString(@"支付成功！");
                [kNotificationCenter postNotificationName:kPaymentDidPaySuccess object:nil];
            }
        }
    }];
}

@end
